package com.ete.service.callback.version

import com.ete.service.entry.version.VersionUpgradeInfo
import com.ete.service.manager.version.VersionManager
import com.ete.service.service.version.VersionHelper
import com.ete.service.util.log.EteLog

/**
 * Author:LiXian
 * <p>
 * Desc:自动检测
 *
 * 注：用于启动时，检测是否需要强制升级，无加载框，返回是否强制升级
 * Version:1.0
 * date 2023/12/19 11:15
 */
abstract class AutoCheckCallback : IVersionCallback {

    override fun onStart() {
        EteLog.d(VersionManager.TAG, "AutoCheckCallback 开始获取最新版本信息")
    }

    override fun onError(errorMsg: String) {
        EteLog.d(VersionManager.TAG, "AutoCheckCallback 获取最新版本信息错误 errorMsg:[${errorMsg}]")
        isUpgradeNotice(false)
    }

    override fun onNoNewVersion() {
        EteLog.d(VersionManager.TAG, "AutoCheckCallback 无最新版本信息")
        isUpgradeNotice(false)
    }

    override fun onVersionInfo(mVersion: VersionUpgradeInfo) {
        EteLog.d(VersionManager.TAG, "AutoCheckCallback 获取到最新版本信息mVersion:[${mVersion}]")
        val isUpgrade = VersionHelper.isNoticeUpgrade(mVersion)
        if (isUpgrade) {
            VersionHelper.showUpgradeDialog(mVersion, mCancelCallback = {
                cancelUpgrade()
            })
        }
        EteLog.d(VersionManager.TAG, "AutoCheckCallback 是否强制升级isUpgrade:[$isUpgrade]")
        isUpgradeNotice(isUpgrade)
    }

    //升级提醒
    abstract fun isUpgradeNotice(isUpgrade: Boolean)

    //取消升级
    abstract fun cancelUpgrade()
}